﻿using LxBasic;

namespace LxCore
{
    public class UserParaCenter : JsObject
    {
        public JsIdentifyList<UserPara.Double> Scalar = new();
        public JsIdentifyList<UserPara.Vector> Vector = new();
        public void Test()
        {
            //    Scalar.Add(new UserPara.Double() { Name = "AmbientTemperature", Parameter = new ConstPara.Double(20) });
            //    Scalar.Add(new UserPara.Double() { Name = "Test", Parameter = new RefUserPara.Double("AmbientTemperature") });
            //    Vector.Add(new UserPara.Vector() { Name = "Gravity", Parameter = new ConstPara.Vector(new Vector3d(0, 0, -9.8)) });
        }
        public override void FromJsonKV(string key, IJsonReader jsReader)
        {
            switch (key)
            {
                case nameof(Scalar): jsReader.ReadList(Scalar, t => new UserPara.Double()); break;
                case nameof(Vector): jsReader.ReadList(Vector, t => new UserPara.Vector()); break;
                default: base.FromJsonKV(key, jsReader); break;
            }
        }
        public override void ToJsonKV(IJsonWriter writer)
        {
            base.ToJsonKV(writer);
            if (Scalar.Count > 0)
            {
                writer.WriteList(nameof(Scalar), Scalar);
            }
            if (Vector.Count > 0)
            {
                writer.WriteList(nameof(Vector), Vector);
            }
        }
    }
}
